//
//  GetBidsDetailViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/18.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "GetBidsDetailViewController.h"

@interface GetBidsDetailViewController ()
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UILabel *headTitle;
@property (weak, nonatomic) IBOutlet UIButton *cancleButton;
@property (weak, nonatomic) IBOutlet UIButton *postButton;


@property (weak, nonatomic) IBOutlet UIImageView *companyIMage;
@property (weak, nonatomic) IBOutlet UILabel *bidName;
@property (weak, nonatomic) IBOutlet UILabel *companyName;

@property (weak, nonatomic) IBOutlet UILabel *companyPerson;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *projectMoney;
@property (weak, nonatomic) IBOutlet UILabel *projectAddress;
@property (weak, nonatomic) IBOutlet UILabel *endTime;
@property (weak, nonatomic) IBOutlet UILabel *serviceRequest;
@property (weak, nonatomic) IBOutlet UILabel *pdfLabel;

@property (weak, nonatomic) IBOutlet UILabel *supplyCompany;
@property (weak, nonatomic) IBOutlet UILabel *supplyMoney;
@property (weak, nonatomic) IBOutlet UILabel *supplyDate;
@property (weak, nonatomic) IBOutlet UILabel *supplyDes;

@end

@implementation GetBidsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    [self getBidDetail];
    [self getCommitBidDetail];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 570), NO);
    
    _cancleButton.layer.cornerRadius = 3*VerticalRatio();
    
    _postButton.layer.borderWidth = 1;
    _postButton.layer.cornerRadius = 2*VerticalRatio();
    _postButton.layer.borderColor = [UIColor colorWithRed:1.000 green:0.565 blue:0.000 alpha:1.000].CGColor;
    
    if ([_bidStatus integerValue]>=3) {
        _headTitle.text = @"中标标书详情";
        _postButton.hidden = NO;
        _cancleButton.hidden = YES;
        _scroView.contentSize = flexibleSize(CGSizeMake(0, 510), NO);
        if ([_bidStatus isEqualToString:@"5"]) {
            _postButton.frame = flexibleFrame(CGRectMake(215, 9, 92, 18), NO);
            [_postButton setTitle:@"买家已收货去评价" forState:UIControlStateNormal];
        }
    }
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark  ==== 去发货
- (IBAction)postGoods:(id)sender {
}

#pragma mark === 取消投标
- (IBAction)cancleHandel:(id)sender {
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_bidId forKey:@"mmsuId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_updateSupplyStatus withHttpType:@"POST" withTag:GS_GS_updateSupplyStatus];
}

#pragma mark === 标书详情
- (void)getBidDetail{
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_bidId forKey:@"mmdeId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryDemandDetail withHttpType:@"POST" withTag:GS_GS_queryDemandDetail];
    
}

#pragma mark === 投标详情
- (void)getCommitBidDetail{
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_bidId forKey:@"mmdeId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryMySupplyDetail withHttpType:@"POST" withTag:GS_GS_queryMySupplyDetail];


}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag == GS_GS_queryDemandDetail){
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"];
            
            _bidName.text = [NSString stringWithFormat:@"%@",dic[@"mmdeName"]];
            _companyPerson.text = [NSString stringWithFormat:@"%@",dic[@"mstoMemberName"]];
            _companyName.text = [NSString stringWithFormat:@"%@",dic[@"mstoName"]];
            
            NSString * image = [NSString stringWithFormat:@"%@",dic[@"mstoImage"]];
            if (image.length>0) {
                [_companyIMage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
            }
            
            _addressLabel.text = [NSString stringWithFormat:@"%@%@",dic[@"citySysArea"][@"AName"],dic[@"proSysArea"][@"AName"]];
            
            NSString * date = [NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"]];
            if (date.length>=10) {
                date = [date substringToIndex:10];
            }
            _dateLabel.text = date;
            
            _projectMoney.text = [NSString stringWithFormat:@"%@",dic[@"mmdePrice"]];
            _projectAddress.text = [NSString stringWithFormat:@"%@",dic[@"mmdeCity"]];
            
            NSString * endTime = [NSString stringWithFormat:@"%@",dic[@"mmdeDueTime"]];
            if (endTime.length>=10) {
                endTime = [endTime substringToIndex:10];
            }
            _endTime.text = endTime;
            
            _serviceRequest.text = [NSString stringWithFormat:@"%@",dic[@"mmdeContent"]];
            
            NSString * pdf = [NSString stringWithFormat:@"%@",dic[@"mmdeAttach"]];
            if (pdf.length>=26) {
                pdf = [pdf substringWithRange:NSMakeRange(11, pdf.length-15)];
            }
            _pdfLabel.text = pdf;
        }
    }else if (tag == GS_GS_queryMySupplyDetail){
    
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"];
            _supplyCompany.text = [NSString stringWithFormat:@"%@",dic[@"supplyMstoName"]];
//            _supplyMoney.text = [NSString stringWithFormat:@"%.2f",[dic[@"mmsuPrice"] floatValue]];
            _supplyDate.text = [NSString stringWithFormat:@"%@",dic[@"mmsuCreateTime"]];
            _supplyDes.text = [NSString stringWithFormat:@"%@",dic[@"mmsuContent"]];
        }
    }else if (tag == GS_GS_updateSupplyStatus){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    [self dismissWaitDialog];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
